var e = require('../@babel/runtime/helpers/regeneratorRuntime.js'),
  n = require('../@babel/runtime/helpers/asyncToGenerator.js'),
  t = getApp();
module.exports = Behavior({
  data: {},
  pageLifetimes: { show: function () {} },
  created: function () {},
  attached: function () {},
  ready: function () {},
  methods: {
    _showCancel: function () {
      var e = this.data.order,
        n = this;
      e.is_award
        ? wx.showModal({
            title: '提示',
            confirmText: '继续',
            cancelText: '关闭',
            content:
              '亲爱的小主，本订单为已中奖订单。【取消订单】后，系统将对本单所中奖品做回收处理，是否确认继续？',
            success: function (e) {
              e.confirm
                ? n.__cancelOrder()
                : e.cancel && console.log('用户点击取消');
            },
          })
        : this.__cancelOrder();
    },
    __handle_xyg_deal: function () {
      return n(
        e().mark(function n() {
          var r, a;
          return e().wrap(
            function (e) {
              for (;;)
                switch ((e.prev = e.next)) {
                  case 0:
                    return (
                      (e.prev = 0),
                      (e.next = 3),
                      t.$api.user.getPositionRules(
                        { position: 'zhima_pay_state' },
                        { loading: !0 },
                      )
                    );
                  case 3:
                    (r = e.sent),
                      (a = null),
                      (a =
                        0 === r.length
                          ? null
                          : r.length >= 2
                            ? r.find(function (e) {
                                return (
                                  e.protocol_content.includes('先用后付') &&
                                  e.protocol_content.includes('订单')
                                );
                              })
                            : r[0])
                        ? wx.navigateTo({
                            url: '/pages/webview/webview?route=rulesDetail&_query='.concat(
                              encodeURIComponent('id=' + a.id),
                            ),
                          })
                        : wx.navigateTo({
                            url: '/pages/webview/webview?route=rulesDetail&_query='.concat(
                              encodeURIComponent('id=' + r[0].id),
                            ),
                          }),
                      (e.next = 12);
                    break;
                  case 9:
                    (e.prev = 9), (e.t0 = e.catch(0)), console.log(e.t0);
                  case 12:
                  case 'end':
                    return e.stop();
                }
            },
            n,
            null,
            [[0, 9]],
          );
        }),
      )();
    },
    __cancelOrder: function () {
      var r = this;
      return n(
        e().mark(function n() {
          var a, o, c;
          return e().wrap(function (e) {
            for (;;)
              switch ((e.prev = e.next)) {
                case 0:
                  return (
                    (a = r),
                    (o = Number(r.data.order.id)),
                    (e.next = 4),
                    t.$api.order.judgeCancel({ id: o })
                  );
                case 4:
                  if (!(c = e.sent) || c.is_can) {
                    e.next = 8;
                    break;
                  }
                  return (
                    wx.showModal({
                      title: '该订单不可取消',
                      showCancel: !1,
                      content: c.message,
                      confirmText: '我知道了',
                    }),
                    e.abrupt('return')
                  );
                case 8:
                  wx.showModal({
                    title: '取消订单？',
                    content:
                      '取消订单后，本单享有的优惠可能会一并取消，是否继续？',
                    success: function (e) {
                      e.confirm
                        ? t.$api.order
                            .cancelMyOrder(
                              { id: o, cause: 14 },
                              { loading: !0, loadingDesc: '请稍候...' },
                            )
                            .then(function (e) {
                              wx.showToast({
                                title: '取消成功',
                                icon: 'none',
                                duration: 800,
                              }),
                                a.triggerEvent('reload');
                            })
                        : e.cancel && console.log('用户点击取消');
                    },
                  });
                case 9:
                case 'end':
                  return e.stop();
              }
          }, n);
        }),
      )();
    },
    __askAfterSale: function () {
      var r = this;
      return n(
        e().mark(function n() {
          var a, o, c, i, s, u, d, l, w, p;
          return e().wrap(function (e) {
            for (;;)
              switch ((e.prev = e.next)) {
                case 0:
                  if (
                    (wx.showLoading(),
                    (a = r.data.order),
                    (o = a.is_sale_over_day),
                    (c = a.sale_over_day_name),
                    (i = a.id),
                    (s = a.type),
                    (u = a.sales_id),
                    !o)
                  ) {
                    e.next = 6;
                    break;
                  }
                  return (
                    wx.hideLoading(),
                    wx.showModal({ title: '提示', content: c, showCancel: !1 }),
                    e.abrupt('return')
                  );
                case 6:
                  if (15 != s) {
                    e.next = 18;
                    break;
                  }
                  return (
                    (e.next = 9),
                    t.$api.order.freeOrderBeforeSalesApply({
                      order_id: i,
                      sales_id: u || '',
                    })
                  );
                case 9:
                  if (
                    ((d = e.sent), wx.hideLoading(), null == d || !d.isToast)
                  ) {
                    e.next = 14;
                    break;
                  }
                  return (
                    wx.showModal({
                      title: '提示',
                      content: d.credit_notice_words || '',
                      showCancel: !1,
                    }),
                    e.abrupt('return')
                  );
                case 14:
                  (l = encodeURIComponent('order_id='.concat(i))),
                    wx.navigateTo({
                      url: '/pages/webview/webview?route=createAfterSale2&_query='.concat(
                        l,
                      ),
                    }),
                    (e.next = 26);
                  break;
                case 18:
                  return (
                    (e.next = 20),
                    t.$api.order.getAfterSaleOrderInfo(
                      { order_id: i },
                      { resolvePlainData: !0 },
                    )
                  );
                case 20:
                  if (((w = e.sent), wx.hideLoading(), 0 == w.code)) {
                    e.next = 24;
                    break;
                  }
                  return e.abrupt('return');
                case 24:
                  (p = encodeURIComponent('order_id='.concat(i))),
                    wx.navigateTo({
                      url: '/pages/webview/webview?route=createAfterSale2&_query='.concat(
                        p,
                      ),
                    });
                case 26:
                case 'end':
                  return e.stop();
              }
          }, n);
        }),
      )();
    },
  },
});
